<template>
  <div class="qualiy_add">
    <el-dialog title="添加拱脚下沉量测数据" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="form" class="demo-form-inline" :model="form" label-width="120px">
        <!-- 必填 -->
        <el-form-item label="断面">
          <el-select style="width:100%" v-model="form.sId" placeholder="请选择断面">
            <el-option v-for="v in TunnelSection" :label="v.sectionName" :key="v.id" :value="v.id"></el-option>
          </el-select>
        </el-form-item>
        <!-- 必填 -->
        <el-form-item label="测量时间">
          <el-date-picker
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期"
              v-model="form.createDate"
              style="width: 100%;"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="GJ1测量值">
          <el-input v-model="form.footValue"></el-input>
        </el-form-item>
        <el-form-item label="GJ2测量值">
          <el-input v-model="form.foot2Value"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="create">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import api from '../../../api'
import qs from 'qs'

export default {
  data() {
    return {
      dialogVisible: false,
      etype: [],
      tunnelList: [],
      TunnelSection: [],
      form: {
        wId: '', //洞幅id
        sId: '', //断面id
        createDate: '',
        footValue: '',
        foot2Value: ''
      }
    }
  },
  mounted() {
    this.$bus.$on('onAddMonitorFootShow', (flag) => {
      if (this.form.wId == '') {
        this.$message({
          type: 'fail',
          message: '请选择洞幅'
        })
        this.dialogVisible = false
      } else {
        this.dialogVisible = true
      }
    })
    this.$bus.$on('onAddMonitorFootWid', (flag) => {
      this.form.wId = flag
      this.findByTunnelSection(this.form.wId)
    })
  },
  methods: {
    // 查询断面
    findByTunnelSection(wid) {
      console.log(wid)
      api
          .tunnelSectionfindByWid({wid})
          .then((res) => {
            if (res.data.code == 2001) {
              console.log(res.data)
              this.TunnelSection = res.data.data
            }
          })
          .catch((err) => {
            console.log(err)
          })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then((_) => {
            done()
          })
          .catch((_) => {
          })
    },
    create() {
      if (this.form.wId == '') {
        this.$message({
          type: 'fail',
          message: '请选择洞幅'
        })
        return
      }
      if (this.form.sId == '') {
        this.$message({
          type: 'fail',
          message: '请选择断面'
        })
        return
      }
      api
          .monitorFootsave(qs.stringify(this.form))
          .then((res) => {
            if (res.data.code == 2001) {
              this.$message({
                type: 'success',
                message: '添加成功!'
              })
              this.dialogVisible = false
              this.$bus.$emit('onRefreshmonitorFoot', {wId: this.form.wId, sId: this.form.sId})
            } else {
              this.$message({
                type: 'fail',
                message: res.data.message
              })
            }
          })
          .catch((err) => {
          })
    },

    onSubmit() {
      console.log('submit!')
    },
    handleCommand(command) {
      alert(command)
    },
    funsection() {
    }
  }
}
</script>

<style scoped>
.qualiy_add {
  width: 1000px;
  margin: 10px;
}

.el-dialog {
  width: 40%;
}
</style>